package com.ynny.test01.controller;

import com.github.pagehelper.PageInfo;
import com.ynny.test01.entity.Order;
import com.ynny.test01.entity.OrderVo;
import com.ynny.test01.entity.R;
import com.ynny.test01.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;


    @GetMapping("/page")
    public R page( OrderVo orderVo){
        PageInfo pageInfo = orderService.findAllOrders(orderVo);
        return R.ok(pageInfo);
    }


    //添加 修改
    @PostMapping("/edit")
    public R edit(@RequestBody Order order){
        if (order.getId() == null){
            orderService.addOrder(order);
        }else {
            orderService.editOrder(order);
        }
        return R.ok(order);
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){

        orderService.deleteOrder(id);

        return R.ok(id);
    }


}
